package com.its.oa.system.Role.service.impl;

import java.util.List;

import com.its.oa.model.Role;
import com.its.oa.system.Role.dao.RoleDao;
import com.its.oa.system.Role.service.RoleService;
import com.its.oa.util.EntityValidata;

public class RoleServiceImpl implements RoleService {
	private RoleDao roleDao;
	public Role findById(int id){
		return roleDao.findById(id);
	}
	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public List<Role> findRolesByUsername(String username) {
		if(EntityValidata.isNotEmpty(username))
			return roleDao.findRolesByUserName(username);
		else
			return null;
	}

	public List<Role> queryAllRole() {
		return roleDao.findAllRole();
	}

	public List<Role> queryAllRoleByPage(int offset, int pagesize) {
		return roleDao.findRoleByPage(offset, pagesize);
	}

	public List<Role> queryRoleListByUserid(int userid) {
		List<Role> list = roleDao.queryRoleListByUserid(userid);
		return list;
	}

	public Role queryRoleByCode(String code) {
		Role role = roleDao.findRoleByCode(code);
		return role;
	}
	
	public List<Role> queryRoleListWithoutAssign(int userid) {
		List<Role> assignRoleList = roleDao.queryRoleListByUserid(userid);
		String roleids ="";
		for (Role role : assignRoleList) {
			roleids+=EntityValidata.isNotEmpty(roleids)?",'"+role.getId()+"'":"'"+role.getId()+"'";
		}
		List<Role> roleList = roleDao.queryRoleListNotinRoleids(roleids);
		return roleList;
	}
	
}
